package com.egao.common.module.validate.controller;

import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.validate.entity.ValidateRule;
import com.egao.common.module.validate.entity.ValidateRuleItem;
import com.egao.common.module.validate.service.ValidateRuleItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 验证规则项控制器
 *
 * @author warmwind
 * @since 2024-11-21 14:04:53
 */
@Api(tags = "验证规则项管理")
@RestController
@RequestMapping("/api/validate/rule-item")
public class ValidateRuleItemController extends BaseController {

    @Resource
    private ValidateRuleItemService validateRuleItemService;

    @PreAuthorize("hasAuthority('validate:rule:save')")
    @ApiOperation("添加验证规则子项")
    @PostMapping()
    public JsonResult save(@RequestBody ValidateRuleItem ruleItem) {
        return validateRuleItemService.insertValidateRuleItem(ruleItem);
    }

    @PreAuthorize("hasAuthority('validate:rule:update')")
    @ApiOperation("修改验证规则子项")
    @PutMapping()
    public JsonResult update(@RequestBody ValidateRuleItem ruleItem) {
        return validateRuleItemService.updateValidateRuleItem(ruleItem);
    }

    @PreAuthorize("hasAuthority('validate:rule:remove')")
    @ApiOperation("删除验证规则子项")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") Integer id) {
        return validateRuleItemService.deleteValidateRuleItem(id);
    }

}
